var util = require('./utils/util')
var request = require('./utils/request.js');
var login = require('./utils/login.js');
var ruoyi = require('./utils/ruoyi.js');

// app.js
App({
  onLaunch() {

    let that = this
    that.request = request
    that.util = util
    that.login = login
    that.ruoyi = ruoyi



  },
  globalData: {
    userInfo: null
  },
  // 未登录获取字典   // /public/dictData/
  getDict(dictCode) {
    return new Promise((resolve, reject) => {
      var postObj = {
        url: '/public/dictData/' + dictCode,
        method: 'get'
      }
      request.loginRequest(postObj).then(res => {
        if (res.data.code === 200) {
          resolve(res)
        }
      })
    })
  },

  //未登录 获取平台详情
  getPlatform(){
    return new Promise((resolve, reject) => {
      var postObj = {
        url: '/public/platform/1',
        method: 'get'
      }
      request.loginRequest(postObj).then(res => {
        if (res.data.code === 200) {
          resolve(res)
        }
      })
    })
  },

  /**
   * 回显数据字典
   * @param {*} datas  字典数组  sys_opinion_type
   * @param {*} value    item.sysOpinionType 字典值
   */
  selectDictLabel(datas, value) {
    for (let index = 0; index < datas.length; index++) {
      const element = datas[index];
      if (element.dictValue == value) {
        return element.dictLabel
        break
      }
    }
    // var actions = [];
    // Object.keys(datas).map((key) => {
    //   if (datas[key].dictValue == ('' + value)) {
    //     actions.push(datas[key].dictLabel);
    //     return false;
    //   }
    // })
    // return actions.join('');
  },
})